<template>
    <div class="card flex justify-center">
        <Button label="controller" severity="primary" @click="enableCtl" />

        <Button label="fullScreen" severity="success" @click="fullScreen" />

        <Button label="max" severity="success" @click="maxScreen" />

        <Button label="notify" severity="success" @click="sendNotify" />

    </div>

</template>


<script setup lang="ts">
import { appWindow } from '@tauri-apps/api/window';
import { register } from '@tauri-apps/api/globalShortcut';
import { onMounted } from "vue";
import { isPermissionGranted, requestPermission, sendNotification } from '@tauri-apps/api/notification';


onMounted(async () => {
    await register('Alt+Z', () => {
        console.log('按下了快捷键');
        maxScreen();
    });
})

var canCtrl = false;

async function enableCtl() {
    console.log('canCtrl', canCtrl);
    canCtrl = !canCtrl;
    await appWindow.setDecorations(canCtrl);
}

async function fullScreen() {
    let full = await appWindow.isFullscreen()
    await appWindow.setFullscreen(!full);
}

async function maxScreen() {
    let max = await appWindow.isMaximized()
    if (max) {
        await appWindow.unmaximize();
    } else {
        await appWindow.maximize();
    }
}

async function sendNotify() {
    let permissionGranted = await isPermissionGranted();
    console.log("发送消息权限", permissionGranted);

    if (!permissionGranted) {
        const permission = await requestPermission();
        permissionGranted = permission === 'granted';
    }
    if (permissionGranted) {
        sendNotification({ title: 'TAURI', body: 'Tauri is awesome!', sound: "Alarm2 " });
    }
}



</script>
